package com.hns.can.report.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.base.entity.SysOperateLogEntity;
import com.hns.can.base.vo.LogConllectionVo;
import com.hns.can.base.vo.LogStatisticVo;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.can.report.vo.LogStatisticParamVo;
import com.hns.can.report.vo.OperateLogParamVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

@Service
public class ReportOperatDateService extends CommonService {
	/**
     * @param conditionVo
     * @return
     * @throws Exception
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2014-10-23
     * @功能说明：日志查询 - 日志列表的数据
     */
    @Transactional
    public Pagination searchOperateLogPage(OperateLogParamVo conditionVo) throws Exception {
        Pagination page = this.myBatisPage("sysOperateLog.getOperateLogCnt", "sysOperateLog.getOperateLogList", conditionVo, SysOperateLogEntity.class);
        return page;
    }
    
    /**
     * @param conditionVo
     * @return
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2014-10-23
     * @功能说明：日志查询 - 导出日志查询的数据
     */
    @SuppressWarnings({"unchecked"})
    @Transactional
    public List getOperateLogList(OperateLogParamVo conditionVo) {
        List list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("sysOperateLog.getOperateLogList", conditionVo), SysOperateLogEntity.class);
        return list;
    }
    
    
    /**
     * @param conditionVo
     * @param request
     * @return
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2014-10-24
     * @功能说明：日志统计 - 日志统计列表数据
     */
    @Transactional
    public Pagination searchLogStatisticPage(LogStatisticParamVo conditionVo) {
        Pagination page = this.myBatisPage("sysOperateLog.getLogStatisticCnt", "sysOperateLog.getLogStatisticList", conditionVo,  LogStatisticVo.class);
        return page;
    }
    
    
    /**
     * @param request
     * @param conditionVo
     * @return
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2014-10-24
     * @功能说明：日志统计 - 导出日志统计的数据
     */
    @SuppressWarnings("unchecked")
    @Transactional
    public List getLogStatisticList(LogStatisticParamVo conditionVo) {
        List list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("sysOperateLog.getLogStatisticList", conditionVo), LogStatisticVo.class);
        return list;
    }
    
    @SuppressWarnings({ "rawtypes", "unchecked" })
	@Transactional
	public List getLogColltTable(CommonParamsVo vo) {
    	List list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysOperateLog.getLogColltTable", vo), LogConllectionVo.class);
		return list;
	}
    
    
    @SuppressWarnings("rawtypes")
	@Transactional
	public List getUsersAccessCollection(CommonParamsVo vo) {
		List tmplist = sqlMapDao.selectList("sysOperateLog.getLogCodeValue", vo);
		String condtStr = "\'"+tmplist.get(0)+"\' as "+tmplist.get(0);
		for(int i=1;i<tmplist.size();i++){
			condtStr += ",\'"+tmplist.get(i)+"\' as "+tmplist.get(i);
		}
		vo.setDataRules(condtStr);
		List list = sqlMapDao.selectList("sysOperateLog.getUsersAccessCollection", vo);
		return list;
	}
    
    @SuppressWarnings("rawtypes")
	@Transactional
	public List getDistributionByFunc(CommonParamsVo vo) {
		List list = sqlMapDao.selectList("sysOperateLog.getDistributionByFunc", vo);
		return list;
	}
    
    @SuppressWarnings("rawtypes")
	@Transactional
	public List getUsersAccessRateByDays(CommonParamsVo vo) {
		List list = sqlMapDao.selectList("sysOperateLog.getUsersAccessRateByDays", vo);
		return list;
	}
    
    @SuppressWarnings("rawtypes")
	@Transactional
	public List getUsersAccessRateByHours(CommonParamsVo vo){
		List list = sqlMapDao.selectList("sysOperateLog.usersAccessRateByHours", vo);
		return list;
	}
    
    @SuppressWarnings("rawtypes")
	@Transactional
    public List getTop10OfQuery(CommonParamsVo vo){
    	List list = sqlMapDao.selectList("sysOperateLog.getTop10OfQuery", vo);
		return list;
    }
	
	@SuppressWarnings("rawtypes")
	@Transactional
	public List getTop10OfFunc(CommonParamsVo vo){
		List list = sqlMapDao.selectList("sysOperateLog.getTop10OfFunc", vo);
		return list;
	}
}
